package com.sunshine.lnuplus.view.AppSetting;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class AppSettingViewModel extends AndroidViewModel {
    private SharedPreferences app_setting_sp;
    private SharedPreferences.Editor editor;
    private int theme;
    private MutableLiveData<Boolean> everydayBackground,checkUpdate;

    public AppSettingViewModel(@NonNull Application application) {
        super(application);
        app_setting_sp = application.getSharedPreferences("app_setting",Context.MODE_PRIVATE);
        editor = app_setting_sp.edit();
        everydayBackground = new MutableLiveData<>();
        checkUpdate = new MutableLiveData<>();

        theme = app_setting_sp.getInt("theme",4);
        everydayBackground.setValue(app_setting_sp.getBoolean("everyday_background",true));
        checkUpdate.setValue(app_setting_sp.getBoolean("check_update",true));
    }

    public int getTheme() {
        return theme;
    }

    public void setTheme(int theme) {
        this.theme = theme;
    }

    public MutableLiveData<Boolean> getEverydayBackground() {
        return everydayBackground;
    }

    public MutableLiveData<Boolean> getCheckUpdate() {
        return checkUpdate;
    }

    public void saveTheme(){
        editor.putInt("theme",theme);
    }

    public void saveEverydayBackground(){
        editor.putBoolean("everyday_background",everydayBackground.getValue());
    }

    public void saveCheckUpdate(){
        editor.putBoolean("check_update",checkUpdate.getValue());
    }

    public SharedPreferences.Editor getEditor() {
        return editor;
    }
}
